namespace IAM.Interface.Common
{
    using IAM.Interface.Model;
    using IAM.Interface.Model.ENUM;
    using IAM.Interface.Model.Interface;
    using System;
    using System.Reflection;
    using System.Xml;

    public class XmlObjConversion
    {
        private AbstractConvertObject _acojb;
        private System.Type _type;
        private IAM.Interface.Model.Interface.IConvertXml _xmlint;
        private XmlNode _xmlnode;

        public XmlObjConversion(IAM.Interface.Model.Interface.IConvertXml xmlint)
        {
            this._type = null;
            this._xmlint = null;
            this._acojb = null;
            this._xmlnode = null;
            this._xmlint = xmlint;
        }

        public XmlObjConversion(ActionType actiontype, string xmldocElementName)
        {
            this._type = null;
            this._xmlint = null;
            this._acojb = null;
            this._xmlnode = null;
            if (xmldocElementName.ToLower() == "requestdata")
            {
                switch (actiontype)
                {
                    case ActionType.IDEN_MANAGE:
                        this._acojb = new Identity();
                        return;

                    case ActionType.IDEN_GETACMODEL:
                        this._acojb = new RequestData();
                        return;

                    case ActionType.IDEN_GETUSERACI:
                        this._acojb = new AccountInfo();
                        return;

                    case ActionType.IDEN_SETUSERACI:
                        this._acojb = new ACI();
                        return;

                    case ActionType.ORG_UPDATE:
                        this._acojb = new OrganizeInfo();
                        return;

                    case ActionType.ORG_CREATE:
                        this._acojb = new OrganizeInfo();
                        return;

                    case ActionType.ORG_DELETE:
                        this._acojb = new OrganizeDeleteParameter();
                        return;

                    case ActionType.DM_GETMODULELIST:
                        this._acojb = new RequestData();
                        return;

                    case ActionType.DM_GETDELEINFO:
                        this._acojb = new AccountInfo();
                        return;

                    case ActionType.DM_SETDELEINFO:
                        this._acojb = new AIDelegations();
                        return;
                }
            }
            else
            {
                switch (actiontype)
                {
                    case ActionType.IDEN_MANAGE:
                        this._acojb = new AccountInfo();
                        return;

                    case ActionType.IDEN_GETACMODEL:
                        this._acojb = new ACMMode();
                        return;

                    case ActionType.IDEN_GETUSERACI:
                        this._acojb = new ACI();
                        return;

                    case ActionType.IDEN_SETUSERACI:
                        this._acojb = new ACI();
                        return;

                    case ActionType.ORG_UPDATE:
                        this._acojb = new ResponseData();
                        return;

                    case ActionType.ORG_CREATE:
                        this._acojb = new ResponseData();
                        return;

                    case ActionType.ORG_DELETE:
                        this._acojb = new ResponseData();
                        return;

                    case ActionType.DM_GETMODULELIST:
                        this._acojb = new Modules();
                        return;

                    case ActionType.DM_GETDELEINFO:
                        this._acojb = new AIDelegations();
                        return;

                    case ActionType.DM_SETDELEINFO:
                        this._acojb = new AIDelegations();
                        return;
                }
            }
        }

        public XmlObjConversion(System.Type type, IAM.Interface.Model.Interface.IConvertXml xmlint)
        {
            this._type = null;
            this._xmlint = null;
            this._acojb = null;
            this._xmlnode = null;
            this._type = type;
            this._xmlint = xmlint;
            string[] assemblynames = type.Assembly.FullName.Split(new char[] { ',' });
            this._acojb = (AbstractConvertObject) Assembly.Load(assemblynames[0]).CreateInstance(this._type.FullName);
        }

        public object ConvertToObj()
        {
            this.AbConvertObj.CurrentXmlNode = this.CurrentXmlNode;
            return this.AbConvertObj.ConvertToObject();
        }

        public string GetXml()
        {
            return this.IConvertXml.XML;
        }

        public AbstractConvertObject AbConvertObj
        {
            get
            {
                return this._acojb;
            }
            set
            {
                this._acojb = value;
            }
        }

        public XmlNode CurrentXmlNode
        {
            get
            {
                return this._xmlnode;
            }
            set
            {
                this._xmlnode = value;
            }
        }

        public IAM.Interface.Model.Interface.IConvertXml IConvertXml
        {
            get
            {
                return this._xmlint;
            }
            set
            {
                this._xmlint = value;
            }
        }

        public System.Type Type
        {
            get
            {
                return this._type;
            }
            set
            {
                this._type = value;
            }
        }
    }
}
